/*----------------------------------------\ | Import an external file to a sas data; | |-------------------------------------------| |--------------------------------------------------------------------| |---------------------------| | Argument: | | infile: the file you want to import; | | outdata: the sas data your want to save the contents of the file;| | dbms: | | ACCESS Microsoft Access database .MDB | | DBF dBASE file .DBF | | WK1 Lotus 1 spreadsheet .WK1 | | WK3 Lotus 3 spreadsheet .WK3 | | WK4 Lotus 4 spreadsheet .WK4 | | EXCEL Excel Version 5 spreadsheet .XLS | | EXCEL4 Excel Version 4 spreadsheet .XLS | | EXCEL5 Excel Version 5 spreadsheet .XLS | | EXCEL97 Excel 97 spreadsheet .XLS | | DLM delimited file (default delimiter is a blank) .* | | CSV delimited file (comma-separated values) .CSV | | TAB delimited file (tab-delimited values) .TXT | | replace: if a file with the same name exists, | | T - overwrite it, | | F - append to it; | |-----------------------------| |--------------------------------------------------------------------| |---------------------------------------| | Example: %import(infile=c:\temp.xls, outdata=attest.covar); | | Usage: %import(infile=, outdata=, dbms=tab, replace=t); | \----------------------------------------*/ %macro import(infile=, /**Input data set ***/ outdata=, /**output excel spread sheet*/ dbms=tab, /**DBMS can be CSV, tab, ...*/ replace=t); /**Replace the existing file? */ /*--------------------------------------------\ | Copy Right: Duo Zhou; | | Created: 7-21-2001 7:23pm; | | Purpose: Import an external file into a sas | | data set; | \--------------------------------------------*/ %let out=%qscan(&outdata,1,%str((),)); %local fileref; %let fileref=%qscan(&infile,1,%str((),""'')); %if &dbms ne %then %do; %let dbms=%upcase(&dbms); %end; %else %do; %let dbms=TAB; %end; %if &replace ne %then %do; %let replace=%upcase(&replace); %end; %else %do; %let replace=T; %end; %if &out ne %then %do; %put --> Note: Wait! The system is importing from an input datafile; %put --> "&fileref" ; %put --> to the data set "&out". ; %if (%quote(&fileref) ne) %then %do; proc import datafile="&fileref" out=&out DBMS=&dbms %if (%quote(%upcase(&replace))=T) %then %do; REPLACE %end;; run; %end; %else %do; %put ==> Alert! You forgot to give me an input datafile.; %end; %end; %else %do; %put ==> Alert! You forgot to give me an output dataset.; %end; %mend import;